package com.ftwj.controller;


import com.ftwj.entity.NoticeInfo;
import com.ftwj.service.NoticeInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公告信息的 Controller
 */
@Slf4j
@RestController
@RequestMapping("/notices")
public class NoticeInfoController {

    @Autowired
    private NoticeInfoService noticeInfoService;

    /**
     * 获取所有公告
     * @return 公告列表
     */
    @GetMapping("/select")
    public List<NoticeInfo> getAllNotices() {
        return noticeInfoService.getAllNotices();
    }


    @GetMapping("/selectById/{id}")
    public ResponseEntity<NoticeInfo> getNoticeById(@PathVariable String id) {
        NoticeInfo notice = noticeInfoService.getNoticeById(id);
        if (notice != null) {
            return ResponseEntity.ok(notice);
        } else {
            return ResponseEntity.notFound().build();
        }

    }
}
